/*
 * Copyright 2010-2011 WebEqua Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.mathcloud.math.core.matlab.quantity;

import org.mathcloud.math.core.matlab.manager.MatlabSupervisor;
import org.webequa.core.common.operator.QuantityObjectOperation;
import org.webequa.core.common.quantity.QuantityObject;
import org.webequa.core.common.signature.QuantityObjectSignature;
//import class Matlab4WebEqua
import Matlab4WebEqua.MatlabEngine;
import com.mathworks.toolbox.javabuilder.MWArray;


public class MatlabQuantityObject implements QuantityObject{
	public MatlabQuantityObject()
	{
		mtlbEngine = MatlabSupervisor.getMatlabEngine();
		mtlbVarName = "Matlab_qnty_"+MatlabSupervisor.getVarId();
	}
	
	@Override
	public QuantityObjectOperation getOperation()
	{
		return null;
	}

	@Override
	public QuantityObjectSignature getSignature()
	{
		return signature;
	}
	
	public MatlabEngine getMatlabEngine()
	{
		return mtlbEngine;
	}
	
	public MWArray getMatlabObject()
	{
		return mtlbObject;
	}
	
	public void setMatlabEngine(MatlabEngine engine)
	{
		mtlbEngine = engine;
	}
	
	public void setMatlabObject(MWArray mObject)
	{
		mtlbObject = mObject;
	}
	
	public String getVarName()
	{
		return mtlbVarName;
	}	

	@Override
	public String toString() {
		if(mtlbObject!=null) {
			return mtlbVarName + "=" + mtlbObject.toString();			
		}
		return "";
	}	
	
	@Override
	protected void finalize()  {
		mtlbObject.dispose();
	}
	
	protected MWArray 					mtlbObject;
	protected MatlabEngine 				mtlbEngine;
	protected String 					mtlbVarName;
	protected QuantityObjectSignature 	signature;
}